

package com.maoshi.shop.distribution.comment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maoshi.shop.common.config.Constant;
import com.maoshi.shop.distribution.comment.dao.DistributionRecruitSetMapper;
import com.maoshi.shop.distribution.comment.model.DistributionRecruitSet;
import com.maoshi.shop.distribution.comment.service.DistributionRecruitSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 *
 * @author lgh on 2019/04/01.
 */
@Service
public class DistributionRecruitSetServiceImpl extends ServiceImpl<DistributionRecruitSetMapper, DistributionRecruitSet> implements DistributionRecruitSetService {

    @Autowired
    private DistributionRecruitSetMapper distributionRecruitSetMapper;

    @Override
    @Cacheable(cacheNames = "DistributionRecruitSet", key = "'0'")
    public DistributionRecruitSet getByShopId() {
        DistributionRecruitSet distributionRecruitSet=distributionRecruitSetMapper.selectOne(new LambdaQueryWrapper<DistributionRecruitSet>()
            .eq(DistributionRecruitSet::getShopId, Constant.PLATFORM_SHOP_ID)
        );
//        if(distributionRecruitSet == null){
//            return createInitialDistributionRecruitSet(shopId);
//        }
        return distributionRecruitSet;
    }

//    @Override
//    public DistributionRecruitSet createInitialDistributionRecruitSet(Long shopId) {
//        DistributionRecruitSet distributionRecruitSet=new DistributionRecruitSet();
//        distributionRecruitSet.setShopId(shopId);
//        distributionRecruitSet.setTitle("分销员推广");
//        distributionRecruitSet.setState(0);
//        distributionRecruitSetMapper.insert(distributionRecruitSet);
//        return distributionRecruitSet;
//    }

    @Override
    @CacheEvict(cacheNames = "DistributionRecruitSet", key = "'0'")
    public void removeCacheByShopId(Long shopId) {

    }

}
